/*
 * Copyright 2011 www.pretty-tools.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include "stdafx.h"
#include "ScriptLogger.h"


// CScriptLogger

DEFINE_LOGGER(CScriptLogger)

CScriptLogger::CScriptLogger()
{
    ATLTRACE( _T("CScriptLogger::CScriptLogger()\n") );
}

CScriptLogger::~CScriptLogger()
{
    ATLTRACE( _T("CScriptLogger::~CScriptLogger()\n") );
}

STDMETHODIMP CScriptLogger::init(BSTR prefix)
{
    if (!prefix || !*prefix)
        return E_INVALIDARG;

    ATLTRACE( L"CScriptLogger::init(\"%s\")\n", prefix );

    CW2A pszPrefix(prefix);
    m_loggerScript.SetPrefix(pszPrefix);

    return S_OK;
}

STDMETHODIMP CScriptLogger::debug(BSTR message)
{
    m_loggerScript.Debug(message);

    return S_OK;
}

STDMETHODIMP CScriptLogger::warn(BSTR message)
{
    m_loggerScript.Warn(message);

    return S_OK;
}

STDMETHODIMP CScriptLogger::error(BSTR message)
{
    m_loggerScript.Error(message);

    return S_OK;
}

STDMETHODIMP CScriptLogger::dumpProperties(VARIANT value)
{
    LOG("dumpProperties(...) is not implemented");

    return S_OK;
}

STDMETHODIMP CScriptLogger::get_isEnabled(VARIANT_BOOL* pVal)
{
    if (!pVal)
        return E_POINTER;

    *pVal = ToVariant(m_loggerScript.IsLogEnabled());

    return S_OK;
}
